/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package sys.donto.telas;

import javax.swing.JOptionPane;
import sys.donto.usuario.Usuario;
import sys.donto.usuario.UsuarioDAO;

/**
 *
 * @author JOABB
 */
public class telaLogin extends javax.swing.JDialog {

    /**
     * Creates new form TelaLogin
     */
    public telaLogin() { // METODO CONSTRUTOR
        initComponents();
       setModal(true);
       setLocationRelativeTo(null);
       setSize(640, 453);
        
        setTitle("sysDONTO - Login"); //Define nome no titulo da tela
        
        UsuarioDAO dao = new UsuarioDAO();
       
        if(dao.listar().size()==0){
            telaUsuario tu = new telaUsuario();
            tu.setVisible(true);
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tfLogin = new javax.swing.JTextField();
        tfSenha = new javax.swing.JPasswordField();
        jLUsuario = new javax.swing.JLabel();
        jLUsuario2 = new javax.swing.JLabel();
        jLSenha = new javax.swing.JLabel();
        jLSenha2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLIcone1 = new javax.swing.JLabel();
        btSair2 = new javax.swing.JButton();
        jLFundo = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        tfLogin.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        getContentPane().add(tfLogin, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 220, 160, -1));

        tfSenha.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        tfSenha.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfSenhaActionPerformed(evt);
            }
        });
        getContentPane().add(tfSenha, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 250, 160, -1));

        jLUsuario.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jLUsuario.setForeground(new java.awt.Color(255, 255, 255));
        jLUsuario.setText("Usuário");
        getContentPane().add(jLUsuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 220, -1, -1));

        jLUsuario2.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jLUsuario2.setForeground(new java.awt.Color(0, 0, 51));
        jLUsuario2.setText("Usuário");
        getContentPane().add(jLUsuario2, new org.netbeans.lib.awtextra.AbsoluteConstraints(300, 220, -1, -1));

        jLSenha.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jLSenha.setForeground(new java.awt.Color(255, 255, 255));
        jLSenha.setText("Senha");
        getContentPane().add(jLSenha, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 250, -1, -1));

        jLSenha2.setFont(new java.awt.Font("Tahoma", 1, 16)); // NOI18N
        jLSenha2.setForeground(new java.awt.Color(0, 0, 51));
        jLSenha2.setText("Senha");
        getContentPane().add(jLSenha2, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 250, -1, -1));

        jButton1.setBackground(new java.awt.Color(255, 255, 255));
        jButton1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jButton1.setForeground(new java.awt.Color(255, 255, 255));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/lock-pp.png"))); // NOI18N
        jButton1.setText("Acessar");
        jButton1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 280, 100, 40));

        jLIcone1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/1413861727_user-128.png"))); // NOI18N
        getContentPane().add(jLIcone1, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 80, -1, -1));

        btSair2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        btSair2.setForeground(new java.awt.Color(255, 255, 255));
        btSair2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/cancel-button-pp.png"))); // NOI18N
        btSair2.setMnemonic('S');
        btSair2.setText("Sair");
        btSair2.setToolTipText("Sair");
        btSair2.setContentAreaFilled(false);
        btSair2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSair2ActionPerformed(evt);
            }
        });
        getContentPane().add(btSair2, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 280, -1, 40));

        jLFundo.setBackground(new java.awt.Color(255, 255, 255));
        jLFundo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/donto/imagens/Login-Papel de parede.jpg"))); // NOI18N
        jLFundo.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        getContentPane().add(jLFundo, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        UsuarioDAO dao = new UsuarioDAO();
        Usuario usu = new Usuario();
        usu.setLogin(tfLogin.getText());
        usu.setSenha(tfSenha.getText());
        if(dao.autentica(usu)){
            //UsuarioAtivo.setUsuario(usu);
            telaMenuPrincipal tp = new telaMenuPrincipal();
            dispose();
            tp.setVisible(true);

        } else {
            JOptionPane.showMessageDialog(rootPane, "Login e/ou senha Incorretos!");
        }
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void tfSenhaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfSenhaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfSenhaActionPerformed

    private void btSair2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSair2ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_btSair2ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(telaLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(telaLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(telaLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(telaLogin.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new telaLogin().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btSair2;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLFundo;
    private javax.swing.JLabel jLIcone1;
    private javax.swing.JLabel jLSenha;
    private javax.swing.JLabel jLSenha2;
    private javax.swing.JLabel jLUsuario;
    private javax.swing.JLabel jLUsuario2;
    private javax.swing.JTextField tfLogin;
    private javax.swing.JPasswordField tfSenha;
    // End of variables declaration//GEN-END:variables

     private String md5(String senha) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
